package com.example.world.servlet;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.example.world.dao.CountryDAO;
import com.example.world.domain.Country;
import com.example.world.domain.PageBean;
import com.example.world.service.CountryService;

@WebServlet("/country")
public class CountryServlet extends HttpServlet
{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException 
	{
		
		// 1. 获取用户提交的参数
		String pageStr = req.getParameter("page");
		if(pageStr == null) pageStr = "1";
		int page = Integer.parseInt(pageStr);
		
		// 2. 调用Service获取分页信息
		CountryService cService = new CountryService();
		PageBean<Country> pageBean = cService.queryPage(page, 10);
		System.out.println(pageBean);

		
		// 3. 显示结果
		// 3.1 方式1 打印输出
		// 3.2 方式2 请求转发jsp
		req.setAttribute("pageBean", pageBean);
		req.getRequestDispatcher("/WEB-INF/jsp/country.jsp").forward(req, resp);
		
		
	
	
	}

}
